package com.ctvit.cch.web.controller;

import com.ctvit.cch.core.pojo.dto.hot.HotRecordAddDTO;
import com.ctvit.cch.core.pojo.dto.hot.HotRecordEditDTO;
import com.ctvit.cch.core.pojo.dto.hot.HotRecordListDTO;
import com.ctvit.cch.core.service.IHotRecordService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 热榜数据Controller
 *
 * @author heyingcheng
 * @date 2025/7/27
 */
@RestController
@RequestMapping("/hot/record")
public class HotRecordController extends BaseController {

    private final IHotRecordService hotRecordService;

    public HotRecordController(IHotRecordService hotRecordService) {
        this.hotRecordService = hotRecordService;
    }

    /**
     * 查询热榜数据列表
     *
     * @param dto 列表参数
     * @return {@link AjaxResult } 数据列表
     */
    @PreAuthorize("@ss.hasPermi('hot:record:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody HotRecordListDTO dto) {
        return hotRecordService.list(dto);
    }

    /**
     * 获取热榜数据详细信息
     *
     * @param id ID
     * @return {@link AjaxResult } 详细信息
     */
    @PreAuthorize("@ss.hasPermi('hot:record:get')")
    @GetMapping(value = "/{id}")
    public AjaxResult get(@PathVariable String id) {
        return success(hotRecordService.get(id));
    }

    /**
     * 新增热榜数据
     *
     * @param dto 新增参数
     * @return {@link AjaxResult } 新增结果
     */
    @PreAuthorize("@ss.hasPermi('hot:record:add')")
    @Log(title = "热点数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody @Validated HotRecordAddDTO dto) {
        return toAjax(hotRecordService.add(dto));
    }

    /**
     * 修改热榜数据
     *
     * @param dto 修改参数
     * @return {@link AjaxResult } 修改结果
     */
    @PreAuthorize("@ss.hasPermi('hot:record:edit')")
    @Log(title = "热点数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody @Validated HotRecordEditDTO dto) {
        return toAjax(hotRecordService.edit(dto));
    }

    /**
     * 删除热榜数据
     *
     * @param ids ID集合
     * @return {@link AjaxResult } 删除结果
     */
    @PreAuthorize("@ss.hasPermi('hot:record:remove')")
    @Log(title = "热点数据", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public AjaxResult remove(@RequestBody List<String> ids) {
        return toAjax(hotRecordService.removeBatchByIds(ids));
    }

    /**
     * 计算聚合评分指定天数内的热点数据
     *
     * @param days 天数，默认值为7
     * @return {@link AjaxResult } 聚合评分结果
     */
    @PreAuthorize("@ss.hasPermi('hot:record:aggregate')")
    @Log(title = "热点数据", businessType = BusinessType.OTHER)
    @PostMapping("/aggregate")
    public AjaxResult aggregate(@RequestParam(defaultValue = "7") int days) {
        return success(hotRecordService.aggregate(days));
    }

    /**
     * 重新分类指定天数内的热点数据
     *
     * @param days 天数，默认值为7
     * @return {@link AjaxResult } 重新分类结果
     */
    @PreAuthorize("@ss.hasPermi('hot:record:recategory')")
    @Log(title = "热点数据", businessType = BusinessType.OTHER)
    @PostMapping("/recategory")
    public AjaxResult recategory(@RequestParam(defaultValue = "7") int days) {
        return success(hotRecordService.recategory(days));
    }

}
